﻿using Domain.Context;
using Microsoft.AspNetCore.Builder;
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;

namespace Domain
{
    public static partial class SeedData
    {
        public static IApplicationBuilder InitializeApplicationDatabase(this IApplicationBuilder app)
        {
#pragma warning disable CS8602 // 解引用可能出现空引用。
            using (var serviceScope = app.ApplicationServices.GetService<IServiceScopeFactory>().CreateScope())
            {
                var context = serviceScope.ServiceProvider.GetRequiredService<ApplicationDBContext>();
                context.Database.Migrate();
            }
#pragma warning restore CS8602 // 解引用可能出现空引用。
            return app;
        }
    }
}
